define(function(require){
    var main =require('/static/main.js');
    require('/static/ajaxfileupload.js');
    var m = new main();
    function Cont(){
        this.Fun._init();
    }
    Cont.prototype.Fun = {
        _init:function(){
            this.getlist();
            this.bindEvent();
        },
        bindEvent:function(){
        },
        getlist:function(){
            var _this = this;
            var emdataa = [];
            var param = {};
            var sort = 0;
            var table = $('#datatable').dataTable({
                'ordering':false,
                "serverSide": true,
                "searching":false,
                'bLengthChange': false,
                'bPaginate': true,
                "bDestory": true,
                "bRetrieve": true,
                "bFilter":false,
                "bSort": false,
                "bProcessing": true,
                "autoWidth": false,
                ajax: function (data, callback, settings) {
                    //封装请求参数
                    param.PageSize = data.length;//页面显示记录条数，在页面显示每页显示多少项的时候
                    param.start = data.start;//开始的记录序号
                    param.PageNo = (data.start / data.length)+1;//当前页码
                    param.ENTCode = _this.ENTCode;//当前页码


                    sort = (param.PageNo-1)*param.PageSize;
                    //ajax请求数据
                    $.ajax({
                        type: "POST",
                        url: "/examine/get-enterprise-apply-list",
                        cache: false,  //禁用缓存
                        data: param,  //传入组装的参数
                        dataType: "json",
                        success: function (result) {
                            var returnData = {};
                            returnData.draw = data.draw;
                            returnData.recordsTotal = result.total;
                            returnData.recordsFiltered = result.total;
                            returnData.data = result.data;
                            emdataa = result.data;
                            callback(returnData);
                        }
                    });
                },
                "aoColumns":[
                    {"mDataProp": 'ENTLogo',
                        "fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
                            $(nTd).html('<img style="with:60px;height:40px;" src="'+oData.ImgHost +oData.ENTLogo +'">');

                        }
                    },
                    {"mDataProp": 'ENTName'},
                    {"mDataProp": 'ShortName'},
                    {"mDataProp": 'ComIndustry',
                        render:function(data){
                            var ComIndustry = '';
                            switch(data){
                                case 100:ComIndustry = '计算机/互联网'; break;
                                case 110:ComIndustry = '日用杂货/家电'; break;
                                case 120:ComIndustry = '商业服务'; break;
                                case 130:ComIndustry = '工业/工业品'; break;
                                case 140:ComIndustry = '金融/保险'; break;
                                case 150:ComIndustry = '教育/出国'; break;
                                case 160:ComIndustry = '生活服务'; break;
                                case 170:ComIndustry = '鞋服/工艺品/奢侈品'; break;
                                case 180:ComIndustry = '媒体/广告/出版'; break;
                                case 190:ComIndustry = '房产/装修/租售'; break;
                                case 200:ComIndustry = '医疗/整形整容'; break;
                                case 210:ComIndustry = '美食餐饮'; break;
                                case 220:ComIndustry = '旅行/出行'; break;
                                case 230:ComIndustry = '美容/保健'; break;
                                case 240:ComIndustry = '手机机数码/通讯服务'; break;
                                case 250:ComIndustry = '汽车/汽配/租赁'; break;
                                case 260:ComIndustry = '休闲娱乐'; break;
                                case 270:ComIndustry = '政府机关/社会组织'; break;

                            }
                            return ComIndustry;
                        }
                    },
                    {"mDataProp": 'CompanyScale',
                        render:function(data){
                            var CompanyScale = '';
                            switch(data){
                                case 1:CompanyScale = '0-300万'; break;
                                case 2:CompanyScale = '300万-1000万'; break;
                                case 3:CompanyScale = '1000万-3000万'; break;
                                case 4:CompanyScale = '3000万-5000万'; break;
                                case 5:CompanyScale = '1亿+'; break;
                            }
                            return CompanyScale;
                        }
                    },
                    {"mDataProp": 'CallName'},
                    {"mDataProp": 'CallPhone'},
                    {"mDataProp": 'CreateTime',
                        render:function(data){
                            return m.formatTimeAll2(data);
                        }
                    },
                    {
                        "mDataProp": "ENTCode",
                        "sClass": "option_btn",
                        "fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
                            // console.log(arguments);
                            $(nTd).html('<span class="btn_detial LookBtn" data-id="'+sData+'">查看</span>\
                                            <span class="btn_detial AuditBtn" data-id="'+sData+'" data-type="100">通过</span>\
                                            <span class="btn_del AuditBtn"  data-id="'+sData+'" data-type="200">拒绝</span>');

                        }
                    }
                ]
            }).api();

            // 点击搜索
            $('#btnSearch').click(function(){
                param.ComName = $('.SearchComName').val();
                var table = $('#datatable').DataTable();
                table.ajax.reload();

            });
            // 点击重置按钮
            $('#btnRefresh').click(function(){
                $('.SearchComName').val('');
                param.ComName = '';
                var table = $('#datatable').DataTable();
                table.ajax.reload();
            });
            //审核
            $(document).on('click','.AuditBtn',function(){
                var type = $(this).attr("data-type");
                var ApplyId = $(this).attr("data-id");
                if(type == '100'){
                    _this.ProbationAudit(ApplyId,200);
                }else{
                    layer.prompt({title: '请填写拒绝理由', formType: 2}, function(text, index){
                        layer.close(index);
                        _this.ProbationAudit(ApplyId,300,text);
                    });
                }
            });
            //查看
            $(document).on('click','.LookBtn',function(){
                var ENTCode = $(this).attr("data-id");
                $.each(emdataa,function(k,v){
                    if(ENTCode == v.ENTCode){

                        var CompanyScale = '';
                        switch(v.CompanyScale){
                            case 1:CompanyScale = '0-300万'; break;
                            case 2:CompanyScale = '300万-1000万'; break;
                            case 3:CompanyScale = '1000万-3000万'; break;
                            case 4:CompanyScale = '3000万-5000万'; break;
                            case 5:CompanyScale = '1亿+'; break;
                        }

                        var ComIndustry = '';
                        switch(v.ComIndustry){
                            case 100:ComIndustry = '计算机/互联网'; break;
                            case 110:ComIndustry = '日用杂货/家电'; break;
                            case 120:ComIndustry = '商业服务'; break;
                            case 130:ComIndustry = '工业/工业品'; break;
                            case 140:ComIndustry = '金融/保险'; break;
                            case 150:ComIndustry = '教育/出国'; break;
                            case 160:ComIndustry = '生活服务'; break;
                            case 170:ComIndustry = '鞋服/工艺品/奢侈品'; break;
                            case 180:ComIndustry = '媒体/广告/出版'; break;
                            case 190:ComIndustry = '房产/装修/租售'; break;
                            case 200:ComIndustry = '医疗/整形整容'; break;
                            case 210:ComIndustry = '美食餐饮'; break;
                            case 220:ComIndustry = '旅行/出行'; break;
                            case 230:ComIndustry = '美容/保健'; break;
                            case 240:ComIndustry = '手机机数码/通讯服务'; break;
                            case 250:ComIndustry = '汽车/汽配/租赁'; break;
                            case 260:ComIndustry = '休闲娱乐'; break;
                            case 270:ComIndustry = '政府机关/社会组织'; break;

                        }

                        var str ='<dt class="">企业Logo：</dt><dd class=""><img src="'+ (v.ImgHost+v.ENTLogo)+'"  style="width:50%;height:100px;"> </dd>\
                            <dt class="m-t-10">企业名称：</dt><dd class="m-t-10">'+ v.ENTName+'</dd>\
                            <dt class="m-t-10">企业简称：</dt><dd class="m-t-10">'+ v.ShortName+'</dd>\
                            <dt class="m-t-10">营业执照：</dt><dd class="m-t-10"><img src="'+ (v.ImgHost+v.License)+'" style="width:50%;height:100px;"> </dd>\
                            <dt class="m-t-10">公司行业：</dt><dd class="m-t-10">'+ComIndustry+' </dd>\
                            <dt class="m-t-10">联系人：</dt><dd class="m-t-10">'+ v.CallName+'</dd>\
                            <dt class="m-t-10">联系人手机：</dt><dd class="m-t-10">'+ v.CallPhone+' </dd>\
                            <dt class="m-t-10">法人姓名：</dt><dd class="m-t-10">'+ v.LegalPersonName+' </dd>\
                            <dt class="m-t-10">法人身份证正面：</dt><dd class="m-t-10"><img src="'+ (v.ImgHost+v.IDCardFront)+'" style="width:50%;height:100px;">  </dd>\
                            <dt class="m-t-10">法人身份证反面：</dt><dd class="m-t-10"><img src="'+ (v.ImgHost+v.IDCardBack)+'" style="width:50%;height:100px;">  </dd>\
                            <dt class="m-t-10">开户行：</dt><dd class="m-t-10">'+ v.OpeningBank+' </dd>\
                            <dt class="m-t-10">银行卡号：</dt><dd class="m-t-10">'+ v.BankId+' </dd>\
                            <dt class="m-t-10">企业规模：</dt><dd class="m-t-10">'+CompanyScale+'</dd>\
                            <dt class="m-t-10">企业所在地址：</dt><dd class="m-t-10">'+ v.ProvinceName+' '+v.CityName+' '+ v.AreaName+' '+ v.Address+'</dd>\
                            <dt class="m-t-10">固定电话：</dt><dd class="m-t-10">'+ v.Tel+'</dd>';
                        $("#Detail .dl-horizontal").html(str);
                        $("#Detail").modal('show');
                        return false;
                    }
                });
            });

        },
        LookBtn:function(){

        },
        ProbationAudit:function(ApplyId,ApplyProcessStatus,Objection){
            $.ajax({
                type: "POST",
                url: "/examine/enterprise-audit",
                data :{EntCode:ApplyId,ApplyProcessStatus:ApplyProcessStatus,Objection:Objection},
                dataType: "json",
                success: function (ret){
                    isactive = false;
                    if(ret.IsBizSuccess){
                        var table1 = $('#datatable').DataTable();
                        table1.ajax.reload();
                    }else{
                        layer.msg(ret.ErrMsg);
                    }
                }
            });
        }
    }
    var a = new Cont();

})